package Java基础.Java类的初始化顺序.实例2;

class Singleton1 {
    private static Singleton1 singleton = new Singleton1();
    public static int value1;
    public static int value2 = 0;
    private Singleton1(){
        value1++;
        value2++;
    }
    public static Singleton1 getInstance(){
        return singleton;
    }
}
class Singleton2{
    public static int value1;
    public static int value2 = 0;
    private static Singleton2 singleton2 = new Singleton2();
    private Singleton2(){
        value1++;
        value2++;
    }
    public static Singleton2 getInstance2(){
        return singleton2;
    }
}

public class  Test{
    public static void main(String[] args) {
        Singleton1 singleton = Singleton1.getInstance();
        System.out.println("value1:" + singleton.value1);
        System.out.println("value2:" + singleton.value2);

        Singleton2 singleton2 = Singleton2.getInstance2();
        System.out.println("value1:" + singleton2.value1);
        System.out.println("value2:" + singleton2.value2);
    }
}
/*
value1:1
value2:0
value1:1
value2:1
 */